package com.heifeng.cloudshelf.mvp.web.activity;

import android.content.Context;
import android.content.Intent;
import androidx.appcompat.app.AppCompatActivity;

import android.view.View;
import android.webkit.WebView;

import com.heifeng.cloudshelf.R;
import com.heifeng.cloudshelf.base.BaseActivity;
import com.heifeng.cloudshelf.mvp.web.contract.WebViewActivityContract;
import com.heifeng.cloudshelf.mvp.web.presenter.WebViewActivityPresenter;

import butterknife.BindView;
import butterknife.OnClick;

public class WebViewActivity extends BaseActivity<WebViewActivityPresenter> implements WebViewActivityContract.View {

    @BindView(R.id.wv_video)
    WebView wv_video;

    private static final String URL_KEY = "url";
    private String url;

    public static void open(Context context,String url) {
        Intent intent = new Intent(context, WebViewActivity.class);
        intent.putExtra(URL_KEY,url);
        context.startActivity(intent);
        //IntentUtil.startActivity(context, WebViewActivity.class);
    }

    @Override
    protected int getLayout() {
        return R.layout.activity_web_view;
    }

    @Override
    protected void initEventAndData() {
        url = getIntent().getStringExtra(URL_KEY);

        mPresenter.initWebView();

        mPresenter.loadUrl(url);
    }

    @Override
    protected void initInject() {
        getActivityComponent().inject(this);
    }

    @OnClick({R.id.l_back})
    public void OnClick(View view) {
        switch (view.getId()) {
            case R.id.l_back:
                finish();
                break;
        }
    }

    @Override
    public WebView getWebView() {
        return wv_video;
    }

    @Override
    protected void onDestroy() {
        mPresenter.destoryWebView();
        super.onDestroy();
    }
}
